﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>商品设置</title>
    <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="../../Content/JS/layer-v1.7.1/layer/layer.js" type="text/javascript"></script>
    <link href="../../Content/Themes/blue2/css.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
      .tep_head{ border-bottom:solid 1px #C6E2FF; background-color:#5291E2; font-size:16px; font-weight:bold;}
      .tep_lis{border-bottom:solid 1px #C6E2FF;}
    .templateName{border: solid 1px #C6E2FF;}
    .templateName  ul li{ padding:10px 10px 10px 10px; text-align:center;}
    .templateName{ float:left; width:200px;}
    .back{ font-weight:bold;  border:solid 2px #5291E2; color:#5291E2;}
    .clickColor{ background-color:#bed3ef;color:#5291E2;font-weight:bold; }
    .show_goods{ float:left; margin-left:50px; width:700px;height:500px;}
    .show_btn{ margin-top:11px; text-align:right; }
      .goods_table{width:700px; border-color:#1C1C1C; overflow:scroll;text-align:center;border-collapse:collapse; border-spacing:0; margin-bottom:10px;  margin-top:5px;}
      .goods_table th,td{ word-break:keep-all; white-space:nowrap;  border:1px black solid ; padding:3px; }
      .pager{ margin-left:25%;  padding-top:20px;}
    </style>
</head>
<body class="main">
     <div class="AllWebTopDiv">
        <div class="path">
            <div class="nav">
                <a href="#">商品设置</a>
            </div>
        </div>
        <div class="content" style=" height:600px;">
           <div class="templateName">
             <ul class="tep_UL">
               <li class="tep_head">产品类别</li>
              
            </ul>
        </div>
         <div class="show_goods">
           <div class="show_btn">
            <input  type="button" value="新增产品" class="button2" onclick="addGoods()"/>
            <input  type="button" value="采购进货" class="button2"  onclick="buyGoods()"/>
            <input  type="button" value="库房退货" class="button2" onclick="OffGoods()"/> 
            <input  type="button" value="导出" class="button2" onclick="daochu()" />
            <input  type="button" value="关闭" id="btn_cancel" onclick="closeWindows();"  class="button2"/>
           </div>
          <table class="goods_table">
             <tr class="DGHeaderStyle">
               <th>商品编号</th>
               <th>商品类别</th>
               <th>商品名称</th>
               <th>计量单位</th>
               <th>商品售价</th>
               <th>促销售价</th>
               <th>商品成本</th>
               <th>是否促销</th> 
               <th>商品数量</th> 
               <th>操作</th>
             </tr>
          </table>
           <div class="pager">
                           <input  type="button" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('首页')"style="cursor:pointer"  value="首页" class="button"/>
                            <input type="button" value="上一页" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('上一页')"style="cursor:pointer" class="button"/>
                            <input type="button" value="下一页" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('下一页')"style="cursor:pointer" class="button"/>
                            <input type="button" value="末页" onmouseover="this.style.fontWeight='bold'" onmouseout="this.style.color='black';this.style.fontWeight='normal'" onclick="newPage('末页')"style="cursor:pointer" class="button"/>
      
       　                    共 <label id="maxPage">1</label> 页 第 <label id="CurrentPage">1</label> 页
                       </div>
         </div>
        </div>
   </div>
</body>
</html>
<script type="text/javascript">


 //加载模板
   $.ajax({
             type:"POST",
             url:"<%:Url.Action("getTepName","Produce") %>",
             data:"",
             cache:false,
             success:function(html){
             $(".tep_UL").append(html);
             }
           })   
    var pageNum=1;
    var pageSize=10;
    var id="";
    window.onload=loadData();
    function loadData() { 
        $.ajax({
            type:"POST",
            url:"<%:Url.Action("GetGoods","Produce") %>",
            data:"pageSize="+pageSize+"&id="+id+"",
            cache:false,
            success:function(txt)
            {
                $(".DGHeaderStyle").nextAll().remove();
                $(".goods_table").append(txt);
                newPage("首页");
            }
           });

              $.ajax({
            type:"POST",
            url:"<%:Url.Action("Data_Load_maxPage","Produce") %>",
            data:"pageSize="+pageSize+"&id="+id+"",
            cache:false,
            success:function(html)
            {
                $("#maxPage").html(html);
               
            }
        });
    }

       function newPage(sa)
        {
           var CurrentPage= $("#CurrentPage").html();
             var maxPage=$("#maxPage").html();
           
            maxPage=parseInt(maxPage);
            
            
            if(sa=="首页")
            {
                pageNum=1;
               document.getElementById("CurrentPage").innerHTML=pageNum;
            }
            if(sa=="下一页")
            {
                 if(CurrentPage>=maxPage)
                {
                     alert("已是最大页数");
                    return;
                }
                pageNum++;
                document.getElementById("CurrentPage").innerHTML=pageNum;
               
            }
            if(sa=="上一页")
            {
                 if(CurrentPage==1)
            {
              alert("已是最小页数");
                return;
            } 
                pageNum--;
                document.getElementById("CurrentPage").innerHTML=pageNum;
            }
            if(sa=="末页")
            {
                pageNum=maxPage;
                 document.getElementById("CurrentPage").innerHTML=pageNum;
            }
              $.ajax({
                type:"POST",
                url:"<%:Url.Action("newPage","Produce") %>",
                data:"pageNum="+pageNum+"&pageSize="+pageSize+"&id="+id+"",
                cache:false,
                success:function(txt)
                {
                   $(".DGHeaderStyle").nextAll().remove();
                   $(".goods_table").append(txt);
                }
            })
        }
    function tep_Over(o) {
        $(o).addClass("back");
    }
    function tep_Out(o) {
        $(o).removeClass("back");
    }
    //选择产品
    function tep_Click(o) {
        var lis = document.getElementsByTagName("li");

        for (var i = 0; i < lis.length; i++) {
            if (lis[i].innerHTML != "产品类别") {
                if (lis[i] != o) {
                    $(lis[i]).removeClass("clickColor");
                }
                else {
                    $(lis[i]).addClass("clickColor");
                }
            }
        }
         id=$(o).attr("id");
         loadData();
    }
   
    //编辑商品
    function  editGoods(o){
        
          $.layer({
                        type: 2,
                        title: false,
                        closeBtn:false,
                       shadeClose: true, //开启点击遮罩关闭层
                        move: ['.juanmove', true],
                       area: ['690px', '340px'],
                       offset: ['100px', ''],
                       iframe: { src: '/Produce/editGoods/?id='+o},
                         success:function(){
                           layer.shift('top',500);
                                  }
                     });
    }
      //新增商品
           function addGoods(){
               $.layer({
                        type: 2,
                        title: false,
                        closeBtn:false,
                       shadeClose: true, //开启点击遮罩关闭层
                        move: ['.juanmove', true],
                       area: ['690px', '340px'],
                       offset: ['100px', ''],
                       iframe: { src: '<%:Url.Action("AddGoods","Produce") %>'},
                         success:function(){
                           layer.shift('top',500);
                                  }
                     });
           
     }
      
     //删除商品
     function delGoods(o){
 
        $.layer({
                  shade:[0.5,'#000',true],
                  area:['310px', '130px'],
                  dialog:{
                      msg:'您确定要删除该方案吗',
                      btns:2,
                      type:4,
                      btn: ['确定','取消'],
                      yes:function(){
                          $.ajax({
                             type:"POST",
                              url:"<%:Url.Action("delGoods","Produce") %>",
                             data:"Id="+o+"",
                             cache:false,
                             success:function(txt){
                              layer.msg(txt,2,function(){location.reload('<%:Url.Action("ProduceInfo","Produce") %>');});
                                 }
                            })

                      },no:function(){
                         layer.closeAll();
                      }
                  }
              
              });
     
     }

     //选择行
     var goodsId="";
      function selectGoods(o){
          $(".goods_table tr").each(
                 function(){
                   var goods=$(this).children("td").eq(0).text();
                    var parseGoodId=parseFloat(goods);
                    if(parseGoodId==o){
                       goodsId=goods;
                       $(this).children().addClass("clickColor");
                    }
                    else{
                     $(this).children().removeClass("clickColor");
                    }
                    
                 }
          
          
          );
      
      }
      //采购进货
      function buyGoods(){
          if(goodsId=="" ||isNaN(parseInt(goodsId))){
            alert("请单击要进货的商品");
            return false;
          }
        $.layer({
                        type: 2,
                        title: false,
                        closeBtn:false,
                       shadeClose: true, //开启点击遮罩关闭层
                        move: ['.juanmove', true],
                       area: ['690px', '340px'],
                       offset: ['100px', ''],
                       iframe: { src: '/Produce/goodsOption/?option=0&goodsId='+goodsId},
                         success:function(){
                           layer.shift('top',500);
                                  }
                     });
      }

        //库房退货
      function OffGoods(){
        
         if(goodsId=="" ||isNaN(parseInt(goodsId))){
            alert("请单击要退货的商品");
            return false;
          }
        $.layer({
                        type: 2,
                        title: false,
                        closeBtn:false,
                       shadeClose: true, //开启点击遮罩关闭层
                        move: ['.juanmove', true],
                       area: ['690px', '340px'],
                       offset: ['100px', ''],
                       iframe: { src: '/Produce/goodsOption/?option=1&goodsId='+goodsId},
                         success:function(){
                           layer.shift('top',500);
                                  }
                     });
      }
      //导出
      function daochu(){
      window.open('<%:Url.Action("ProduceToExcel","Produce") %>');
      }
      //关闭窗口
    function closeWindows() {
        window.location.href = "/Loading/Index/?src=/Desktop/Index/";
    }
</script>